<?php

namespace app\admin\controller;

use auth\Auth;
use think\Controller;
use think\Request;

class Common extends Controller
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $auth = new \auth\Auth();
        $request = Request::instance();
        $name = $request->module() . '/' . $request->controller() . '/' . $request->action();
        $userinfo = cookie('username');
        if (!$userinfo) {
            $this->redirect('login/index');
        }
        $user = base64_decode($userinfo);
        $id = explode(',', $user);
        if (!isset($id[1])) {
            $this->redirect('login/index');
        }
        $user = db('user')->where('uid', $id[1])->find();
        if ($user['r_id'] == 1) {
            return true;
        } else if (!$auth->check($name, $user['uid'])) {
            /* return array('status'=>'error','msg'=>'有权限！');*/
            $this->redirect('error/index');
       } else {
            return true;
        }
    }
}
